### Maryland Truth Commission Script 

# set working directory 
setwd("~/Dropbox/Works_in_Progress/Maryland_Project/")

#set libraries 
library(tidyverse)
library(Hmisc)
library(emmeans)
library(ggeffects)
library(poliscidata)
library(car)
library(effects)
library(gmodels)
library(gridExtra)
library(psych)
library(varhandle)
library(haven)

# load data 
MD_survey<- read_sav("Maryland Survey combined 12.16 (weighted).sav")

# Treatment
MD_survey <- MD_survey %>%
  mutate(treatment = factor(ifelse(MD_survey$VAR00001 == 1, "Lynchings", "Police Killings")))

MD_survey$treatment <- relevel(MD_survey$treatment, ref = "Police Killings")

MD_survey <- MD_survey

# DV -  Support for symbolic TJ measures

MD_survey<- MD_survey %>%
  mutate(public_apology_tj = ifelse(q0009 < 3, 1, 0),
         memorial_plaque_tj = ifelse(q0008 < 3, 1, 0)) %>%
  mutate(symbolic_tj_index = public_apology_tj +
           memorial_plaque_tj)

# DV - support for material TJ measures
MD_survey <- MD_survey  %>%
  mutate(direct_financial_tj = ifelse(q0010 < 3, 1, 0),
         community_projects_tj = ifelse(q0011 < 3, 1, 0)) %>%
  mutate(material_tj_index = direct_financial_tj +
           community_projects_tj)

# truth commission support 
MD_survey <- MD_survey %>%
  mutate(tc_physical = ifelse(q0014 == 3, NA,
                              ifelse(q0014 == 1, 1, 0)),
         tc_inequality = ifelse(q0015 == 3, NA,
                                ifelse(q0015 == 1, 1, 0)),
         tc_discrimination = ifelse(q0016 == 3, NA,
                                    ifelse(q0016 == 1, 1, 0)))





# Primes 
MD_survey <- MD_survey %>%
  mutate(Historical_Context = ifelse(VAR00002 == 1, 0, 1))


##### Demographic Info 
# Age
MD_survey <- MD_survey %>%
  dplyr::rename(age = q0003)


# Gender 
MD_survey <- MD_survey %>%
  mutate(gender = ifelse(q0004 == 4, NA,
                  ifelse(q0004 == 3, NA, 
                  ifelse(q0004 == 2, "Woman", "Man"))))

# Education - Bachelor's Degree 
MD_survey <- MD_survey %>%
  mutate(edu_level = ifelse(q0019 >= 4, 1, 0))

# maryland roots 
MD_survey <- MD_survey %>%
  mutate(maryland_roots = ifelse(q0022 == 1, 0,
                ifelse(q0022 == 2, 1,
                ifelse(q0022 == 3, 2,
                 ifelse(q0022 == 4, 3,
                 ifelse(q0022 == 5, 4, NA))))))

# Awareness of TJ efforts 
MD_survey <- MD_survey %>%
  mutate(maryland_tj_awareness = ifelse(q0028 == 1, "Yes", "No"))

#### Historical Knowledge 
MD_survey <- MD_survey %>%
  mutate(lynching_episodes_number = ifelse(q0005 == 4, 1, 0))

MD_survey <- MD_survey %>%
  mutate(lynching_episodes_location = ifelse(q0006 == 2, 1, 0))

MD_survey <- MD_survey %>%
  mutate(ida_b_wells = ifelse(q0007 == 2, 1, 0))


MD_survey <- MD_survey %>%
  mutate(hist_knowl_index = lynching_episodes_number +
           lynching_episodes_location +
           ida_b_wells)

# Participation in historically Black religious institutions
MD_survey <- MD_survey %>%
  mutate(relig_attendance = ifelse(q0026 <= 3, 1, 0),
         black_protestant = ifelse(q0025 <= 10 & q0025 >= 1, 1, 0)) %>%
  mutate(protestant_religious = ifelse(relig_attendance == 1 & black_protestant == 1, 1, 0))

# Linked Fate 
MD_survey <- MD_survey %>%
  mutate(linked_fate = ifelse(q0034 == 1 & q0035 == 1, 1, 
                      ifelse(q0034 == 1 & q0035 == 2, .66,
                      ifelse(q0034 == 1 & q0035 == 3, .33, 0))))

# Police Exposure 
MD_survey <- MD_survey %>%
  mutate(police_exposure = ifelse(q0049 == 1, 1, 0),
         prison_exposure = ifelse(q0050 == 1 | q0051 <= 2, 1, 0)) %>%
  mutate(violence_exposure = ifelse(police_exposure == 1 | prison_exposure == 1, 1, 0))

# Black Nationalism 
MD_survey <- MD_survey %>%
  mutate(black_only_orgs = ifelse(q0037 == 6, NA,
                                  ifelse(q0037 == 1 | q0037 == 2, 1, 0)),
         own_party = ifelse(q0033 == 6, NA,
                                  ifelse(q0033 == 1 |q0033 == 2, 1, 0))) %>%
  mutate(black_nationalism = ifelse(black_only_orgs == 1 & own_party == 1, 1, 0))

# BLM knowledge 

MD_survey <- MD_survey %>%
  mutate(blm_knowledge = ifelse(q0043 > 2 | q0044 > 2, 0, 1))


MD_survey <- MD_survey %>%  mutate(county = ifelse(q0021 == 1, "Allegany", 
        ifelse(q0021 == 2, "Carroll", 
        ifelse(q0021 == 3, "Harford", 
        ifelse(q0021 == 4, "Marys", 
        ifelse(q0021 == 5, "Anne Arundel", 
        ifelse(q0021 == 6, "Cecil", 
        ifelse(q0021 == 7, "Howard", 
        ifelse(q0021 == 8, "Somerset", 
        ifelse(q0021 == 9, "Baltimore City", 
        ifelse(q0021 == 10, "Charles", 
        ifelse(q0021 == 11, "Kent", 
        ifelse(q0021 == 12, "Talbot", 
        ifelse(q0021 == 13, "Baltimore", 
        ifelse(q0021 == 14, "Dorchester", 
        ifelse(q0021 == 15, "Montgomery", 
        ifelse(q0021 == 16, "Washington", 
        ifelse(q0021 == 17, "Calvert", 
        ifelse(q0021 == 18, "Frederick", 
        ifelse(q0021 == 19, "Prince Georges", 
        ifelse(q0021 == 20, "Wicomico", 
        ifelse(q0021 == 21, "Caroline", 
        ifelse(q0021 == 22, "Garrett", 
        ifelse(q0021 == 24, "Worcester", NA))))))))))))))))))))))))


MD_survey <- MD_survey %>%  mutate(maj_Black_County = ifelse(q0021 == 1, 0, 
                     ifelse(q0021 == 2, 0, 
                     ifelse(q0021 == 3, 0, 
                     ifelse(q0021 == 4, 0,  
                     ifelse(q0021 == 5, 0, 
                     ifelse(q0021 == 6, 0, 
                     ifelse(q0021 == 7, 0, 
                     ifelse(q0021 == 8, 0, 
                     ifelse(q0021 == 9, 1, 
                    ifelse(q0021 == 10,1, 
                    ifelse(q0021 == 11, 0, 
                    ifelse(q0021 == 12, 0, 
                   ifelse(q0021 == 13, 1, 
                   ifelse(q0021 == 14, 0, 
                   ifelse(q0021 == 15, 1, 
                   ifelse(q0021 == 16, 0, 
                    ifelse(q0021 == 17, 0, 
                    ifelse(q0021 == 18, 0, 
                    ifelse(q0021 == 19, 1, 
                    ifelse(q0021 == 20, 0, 
                     ifelse(q0021 == 21, 0, 
                     ifelse(q0021 == 22, 0, 
                     ifelse(q0021 == 24, 0, NA))))))))))))))))))))))))



###### Table 2: Effect of Treatment on Support for Transitional Justice: Simple Mean Differences###### 

# symbolic - model 1
diff_s<- lm(symbolic_tj_index ~ treatment,
                          data = MD_survey)

summary(diff_s)

library(emmeans)

emmeans(diff_s, pairwise ~ treatment)

# material - model 2 
diff_m <- lm(material_tj_index ~ treatment,
                           data = MD_survey)
summary(diff_m)
########################

#### Table 3: Effect of Treatment on Support for Symbolic Transitional Justice: Multivariate Regression

# Treatment + Demographics (model 2)
model_s1 <- lm(symbolic_tj_index ~ treatment +  hist_knowl_index + age + gender + edu_level +  maryland_roots + maryland_tj_awareness,
                          data = MD_survey)

summary(model_s1)



# Treatment +  Linked Fate Interaction (model 3) 
model_s_3 <- lm(symbolic_tj_index ~ treatment*linked_fate+  hist_knowl_index + age + gender + edu_level + maryland_roots + maryland_tj_awareness,
                       data = MD_survey)


summary(model_s_3)


# Treatment + Police Exposure Interaction (model 4)
model_s_4 <- lm(symbolic_tj_index ~ treatment*police_exposure+ hist_knowl_index + age + gender + edu_level + maryland_roots  + maryland_tj_awareness,
                data = MD_survey)

summary(model_s_4)


# Treatment +  Black organizations Interaction (model 5)
model_s_5 <- lm(symbolic_tj_index ~ treatment*protestant_religious + hist_knowl_index + age + gender + edu_level + maryland_roots +  maryland_tj_awareness,
                data = MD_survey)

summary(model_s_5)



# Treatment + Black Nationalism Interaction (model 6)
model_s_6 <- lm(symbolic_tj_index ~ treatment*black_nationalism +  hist_knowl_index + age + gender + edu_level + maryland_roots +  maryland_tj_awareness,
                data = MD_survey)


summary(model_s_6)

library(stargazer)

stargazer(diff_s,
          model_s1, 
          model_s_3, 
          model_s_4, 
          model_s_5,
          model_s_6, 
          type = "html",
          out = "Table3.html", 
          title = "Effect of Treatment on Support for Symbolic Transitional Justice: Multivariate Regression", 
          covariate.labels = c("Historical Violence Treatment", "Linked Fate", "Police Contact",
                               "Black Church Involvement", "Black Nationalism", "Prior Knowledge of Lynchings",
                               "Age", "Woman", "Education Level", "Maryland Roots", "Knowledge of Maryland TJ Programs", 
                               "Historical Violence Treatment x Linked Fate", 
                               "Historical Violence x Police Exposure", "Historical Violence Treatment x Black Church Involvement", 
                               "Historical Violence Treatment x Black Nationalism", "Constant"),
          dep.var.labels  = "Symbolic TJ Index")


########## Table 4: Effect of Treatment on Support for Material Transitional Justice: Multivariate Regression
# Treatment + Demographics (model 2)
model_m1 <- lm(material_tj_index ~ treatment +  hist_knowl_index + age + gender + edu_level + maryland_roots + maryland_tj_awareness,
               data = MD_survey)

summary(model_m1)


# Treatment +  Linked Fate Interaction (model 3) 
model_m_3 <- lm(material_tj_index ~ treatment*linked_fate + hist_knowl_index + age + gender + edu_level + maryland_roots +  maryland_tj_awareness, 
                    data = MD_survey)


summary(model_m_3)


# Treatment + Police Exposure Interaction (model 4)
model_m_4 <- lm(material_tj_index ~ treatment*police_exposure +  hist_knowl_index +age + gender + edu_level + maryland_roots +  hist_knowl_index + maryland_tj_awareness, 
                    data = MD_survey)

summary(model_m_4)


# Treatment +  Black organizations Interaction (model 5)
model_m_5 <- lm(material_tj_index ~ treatment*protestant_religious +hist_knowl_index  + age + gender + edu_level + maryland_roots +  maryland_tj_awareness, 
                    data = MD_survey)

summary(model_m_5)

# Treatment + Black Nationalism Interaction (model 6)
model_m_6 <- lm(material_tj_index ~ treatment*black_nationalism +  hist_knowl_index + age + gender + edu_level + maryland_roots +maryland_tj_awareness , 
                    data = MD_survey)

summary(model_m_6)


##### Appendix Table A1: Differences in Historical and Contemporary Knowledge Across Treatment Groups #####

# model 1
model_a1 <- lm(hist_knowl_index ~ treatment, data = MD_survey)

summary(model_a1)

# model 2 

model_a2 <- lm(hist_knowl_index ~ treatment*Historical_Context, data = MD_survey)

summary(model_a2)

# model 3 

model_a3 <- lm(blm_knowledge ~ treatment, data = MD_survey)

summary(model_a3)



stargazer(diff_m,
          model_m1, 
          model_m_3, 
          model_m_4, 
          model_m_5,
          model_m_6, 
          type = "html",
          out = "Table4.html", 
          title = "Effect of Treatment on Support for Material Transitional Justice: Multivariate Regression", 
          covariate.labels = c("Historical Violence Treatment", "Linked Fate", "Police Contact",
                               "Black Church Involvement", "Black Nationalism", "Prior Knowledge of Lynchings",
                               "Age", "Woman", "Education Level", "Maryland Roots", "Knowledge of Maryland TJ Programs", 
                               "Historical Violence Treatment x Linked Fate", 
                               "Historical Violence x Police Exposure", "Historical Violence Treatment x Black Church Involvement", 
                               "Historical Violence Treatment x Black Nationalism", "Constant"),
          dep.var.labels  = "Material TJ Index")



###################################
# Table A2: Effect of Treatment on Support for Symbolic Transitional Justice: Multivariate Regression, Accounting for Connection to Maryland

# # model 1 - Maryland roots models 
model_s_10 <- lm(symbolic_tj_index ~ treatment*maryland_roots + age + gender + edu_level  + hist_knowl_index + maryland_tj_awareness,
                       data = MD_survey)

summary(model_s_10)


# model 2 - Maryland County models 
model_s_11 <- lm(symbolic_tj_index ~ treatment*maj_Black_County + maryland_roots + age + gender + edu_level  + hist_knowl_index + maryland_tj_awareness,
                        data = MD_survey)

summary(model_s_11)

# # model 3 - Maryland roots models 
model_m_10 <- lm(material_tj_index ~ treatment*maryland_roots + age + gender + edu_level  + hist_knowl_index + maryland_tj_awareness,
                 data = MD_survey)

summary(model_m_10)

# model 4 - Maryland County models 

model_m_11 <- lm(material_tj_index ~ treatment*maj_Black_County +maryland_roots + age + gender + edu_level  + hist_knowl_index + maryland_tj_awareness,
                     data = MD_survey)

summary(model_m_11)

stargazer(model_s_10, model_s_11,  model_m_10,  model_m_11)

#### Table A3: Effect of Treatment on Support for Transitional Justice: Multivariate Regression, Accounting for Age and Age Cohort #### #### 

# alternative specification of age 
MD_survey$age2 <- as.factor(MD_survey$age)

# model 1 - age as categorical variable - symbolic DV 
model_s14 <- lm(symbolic_tj_index ~ treatment*age2 + gender + edu_level +  hist_knowl_index + maryland_roots + maryland_tj_awareness,
                data = MD_survey)

summary(model_s14)

# model 2 age as continuous variable - symbolic DV 
model_s15 <- lm(symbolic_tj_index ~ treatment*age + gender + edu_level +  hist_knowl_index + maryland_roots + maryland_tj_awareness,
                data = MD_survey)

summary(model_s15)

# model 3 - age as categorical variable - material DV 

model_m14 <- lm(material_tj_index ~ treatment*age2 + gender + edu_level +  hist_knowl_index + maryland_roots + maryland_tj_awareness,
                data = MD_survey)

summary(model_m14)

# model 4 - age as continuous variable - material DV 

model_m15 <- lm(material_tj_index ~ treatment*age + gender + edu_level +  hist_knowl_index + maryland_roots + maryland_tj_awareness,
                data = MD_survey)

summary(model_m15)

stargazer(model_s14, model_s15, model_m14, model_m15)














